//修改学生的信息
//导入数据库的连接
const db = require('../db/index')

module.exports.adminstudent = (req, res) => {
  const userInfo = req.body
  const sqlStr = 'update Student set name=?,id=?,adress=? WHERE Student.id=?'
  db.query(sqlStr, [userInfo.username, userInfo.id, userInfo.adress, userInfo.id], (err, result) => {
    if (err) {
      return res.send({
        status: 403,
        message: '修改失败'
      })
    }
    if (result.affectedRows === 0) {
      return res.send({
        status: 403,
        message: '该学生的id不存在'
      })
    }
    if (result.affectedRows != 0) {
      return res.send({
        status: 200,
        message: '修改成功(根据id修改学生信息)',
        data: userInfo
      })
    }
  })
}